package com.servers.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.print.attribute.HashAttributeSet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dao.CakeAdminDao;
import com.entity.CakeAdmin;
import com.servers.CakeAdminService;

@Service("cakeAdminService")
public class CakeAdminServiceImpl implements CakeAdminService {
	@Autowired
	private CakeAdminDao cakeAdminDao;
	@Override
	public List<CakeAdmin> findAllCakeAdmins() {
		// TODO Auto-generated method stub
		return cakeAdminDao.findAllCakeAdmins();
	}

	@Override
	public List<CakeAdmin> findCakeAdminLimit(int a, int b) {
		// TODO Auto-generated method stub
		return cakeAdminDao.findCakeAdminLimit(a, b);
	}

	public CakeAdminDao getCakeAdminDao() {
		return cakeAdminDao;
	}

	public void setCakeAdminDao(CakeAdminDao cakeAdminDao) {
		this.cakeAdminDao = cakeAdminDao;
	}

	@Override
	public List<CakeAdmin> findLikeCake(String cakename) {
		// TODO Auto-generated method stub
		return cakeAdminDao.findLikeCake(cakename);
	}

	@Override
	public List<CakeAdmin> findUpOrDownCake(String cakestatus) {
		// TODO Auto-generated method stub
		return cakeAdminDao.findUpOrDownCake(cakestatus);
	}

	@Override
	public int updateCakeStausById(int cakeid, String cakestatus) {
		// TODO Auto-generated method stub
		return cakeAdminDao.updateCakeStausById(cakeid, cakestatus);
	}

	@Override
	public int updateCakePeiceById(int cakeid, double cakeprice) {
		// TODO Auto-generated method stub
		return cakeAdminDao.updateCakePeiceById(cakeid, cakeprice);
	}

	@Override
	public int updateCakeUpPeiceById(int cakeid, double cakeupprice) {
		// TODO Auto-generated method stub
		return cakeAdminDao.updateCakeUpPeiceById(cakeid, cakeupprice);
	}
	
	/**
	 * 将查询的 list 集合 封装为固定的 表格参数 格式 模板
	 * @param list
	 * @return
	 */
	public List<Map<String, Object>> getListMap(List<CakeAdmin> list){
		List<Map<String, Object>> listmap=new ArrayList<>();
		for (CakeAdmin cake : list) {
			Map<String, Object> tempmap=new HashMap<>();
			tempmap.put("id", cake.getCakeId());
			tempmap.put("cakename", cake.getCakeName());
			tempmap.put("cakeprice", cake.getCakePrice());
			tempmap.put("cakeupprice", cake.getCakeupPrice());
			tempmap.put("cakesales", cake.getCakeSales());
			tempmap.put("cakecontext", cake.getCakeContext());
			int id=cake.getCaketypeId();
			if (id==2 || id==3 || id==4 || id==5) {
				tempmap.put("type", "蛋糕");
			}else if (id==6) {
				tempmap.put("type", "吐司");
			}else if (id==7) {
				tempmap.put("type", "礼品");
			}
			listmap.add(tempmap);
		}
		
		return listmap;
	}

	@Override
	public int updateCakeAdminByid(CakeAdmin cakeAdmin) {
		// TODO Auto-generated method stub
		return cakeAdminDao.updateCakeAdminByid(cakeAdmin);
	}

	@Override
	public int addCakeAdmin(CakeAdmin cakeAdmin) {
		// TODO Auto-generated method stub
		return cakeAdminDao.addCakeAdmin(cakeAdmin);
	}
	
	
}
